#include "Drawable.h"

//=====CONSTRUCTORS
Drawable::Drawable()
	:m_vecPosition(ScreenW*.5,ScreenH*.5,0),
	m_vecScale(0.5f,0.5f,0.5f),
	m_eiIdentifier(0),
	BlackCtr(255)
{
	m_Color = D3DCOLOR_ARGB(255,255,255,255);
	D3DXMATRIX				m_matRotation;		//Temporarily stores rotation	
	D3DXMatrixIdentity		(&m_matRotation);
	D3DXMatrixScaling		(&m_matScale,m_vecScale.x,m_vecScale.y, 1.0f);	
	D3DXMatrixTranslation	(&m_matTranslation,m_vecPosition.x,m_vecPosition.y, 0); 
	D3DXMatrixMultiply		(&m_matWorldTrans,&m_matRotation, &m_matTranslation);	
	D3DXMatrixMultiply		(&m_matWorldTrans,&m_matScale,&m_matWorldTrans);
};
Drawable::Drawable(float Xpos, float Ypos, float Xsca, float YSca, int ID,int TexID)
	:m_vecPosition(Xpos,Ypos,0),
	m_vecScale(Xsca,YSca,0.5f),
	m_eiIdentifier(ID),
	m_eiTextureIndex(TexID),
	BlackCtr(255)
{

	m_Color = D3DCOLOR_ARGB(255,255,255,255);

	D3DXMATRIX				m_matRotation;		//Temporarily stores rotation	
	D3DXMatrixIdentity		(&m_matRotation);
	D3DXMatrixScaling		(&m_matScale,m_vecScale.x,m_vecScale.y, 1.0f);	
	D3DXMatrixTranslation	(&m_matTranslation,m_vecPosition.x,m_vecPosition.y, 0); 
	D3DXMatrixMultiply		(&m_matWorldTrans,&m_matRotation, &m_matTranslation);	
	D3DXMatrixMultiply		(&m_matWorldTrans,&m_matScale,&m_matWorldTrans);
};
//=====MUTATORS
void Drawable::PhaseToYellow(int B,int G)
{
	m_Color = D3DCOLOR_ARGB(255,255,G,B);

}
void Drawable::PhaseToRed(int x)
{
	m_Color = D3DCOLOR_ARGB(255,255,x,0);
}
void Drawable::PhaseToBlack(int x)
{
	if(BlackCtr > 0)
	{
		BlackCtr-=1;
		m_Color = D3DCOLOR_ARGB(255,BlackCtr,0,0);
	}
	else if(BlackCtr <= 0)
	{
		BlackCtr = 0;
		m_Color = D3DCOLOR_ARGB(255,BlackCtr,0,0);
	}
}
void Drawable::SetToColor(int Color)
{
	switch(Color)
	{
	case RED:	m_Color = D3DCOLOR_ARGB(255,255,0,0);	break;
	case BLUE:	m_Color = D3DCOLOR_ARGB(255,0,0,255);	break;
	case GREEN:	m_Color = D3DCOLOR_ARGB(255,0,255,0);	break;
	case BLACK:	m_Color = D3DCOLOR_ARGB(255,0,0,0);		break;
	case YELLOW:m_Color = D3DCOLOR_ARGB(255,255,255,0);	break;
	}

}
//=====UPDATE
void Drawable::Update()
{
	D3DXMATRIX				m_matRotation;		//Temporarily stores rotation	
	D3DXMatrixIdentity		(&m_matRotation);
	D3DXMatrixScaling		(&m_matScale,m_vecScale.x,m_vecScale.y, 1.0f);	
	D3DXMatrixTranslation	(&m_matTranslation,m_vecPosition.x,m_vecPosition.y, 0); 
	D3DXMatrixMultiply		(&m_matWorldTrans,&m_matRotation, &m_matTranslation);	
	D3DXMatrixMultiply		(&m_matWorldTrans,&m_matScale,&m_matWorldTrans);	
};